#!/usr/bin/env perl

use warnings;
use strict;

for my $game (@ARGV) {
    open my $fh, $game or die "can't open $game: $!";
    my @data = <$fh>;
    chomp @data;
    close $fh or die "can't close $game: $!\n";
    my ($pb,$br,$pw,$wr,$size,$komi,$date) = @data[2,3,5,6,8,10,16];
    my ($year, $month, $day) = split /\s/, $date;
    print "(SZ[$size]PB[$pb]BR[$br]PW[$pw]WR[$wr]KM[$komi]DT[$year-$month-$day]\n";

    splice @data, 0, 21;
    for my $move (@data) {
        my ($color, $x, $y) = split /\s/, $move;
        $_ = chr(ord('a') + $_) for $x, $y;
        print ";$color\[$x$y]"
    }
    print ")\n";
}

__END__

A WWG file might look like:

4
2.0
inoriyouko
4D

imai kazuhiro
5D

9
0
6.5
0
0
2
0.5
m503
1999 12 26 00 00 GMT 
0
0
 
63
B 3 2 0 
W 4 5 0 
B 4 4 0 
W 3 4 0 
B 5 4 0 
W 3 3 0 
B 4 2 0 
W 5 5 0 
B 6 5 0 
W 3 5 0 
B 6 6 0 
W 2 2 0 
B 2 1 0 
W 1 1 0 
B 1 2 0 
W 2 3 0 
B 1 0 0 
W 3 1 0 
B 0 1 0 
W 4 3 0 
B 5 3 0 
W 5 2 0 
B 4 1 0 
W 5 1 0 
B 3 0 0 
W 7 3 0 
B 6 4 0 
W 7 1 0 
B 5 7 0 
W 4 7 0 
B 6 2 0 
W 6 1 0 
B 6 3 0 
W 7 2 0 
B 7 4 0 
W 8 0 0 
B 2 6 0 
W 2 7 0 
B 3 6 0 
W 3 7 0 
B 1 4 0 
W 1 6 0 
B 2 5 0 
W 5 6 0 
B 6 7 0 
W 1 5 0 
B 1 3 0 
W 1 8 0 
B 2 4 0 
W 4 6 0 
B 8 3 0 
W 8 2 0 
B 8 4 0 
W 5 8 0 
B 6 8 0 
W 4 8 0 
B 8 7 0 
W 0 4 0 
B 0 3 0 
W 0 5 0 
B 5 0 0 
W 6 0 0 
B 4 0 0 
